﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Linq.Expressions;
using Microsoft.VisualBasic;
using static ExpressionTest.ExpressionHelper;
using static Entities.TestEntities;
using Entities;

namespace ExpressionTest
{
    public class ExpressionProduct
    {
        public static void Go()
        {


            Expression<Func<Product, bool>> whereLambda = x => x.Price > 200;
            whereLambda = whereLambda.And(x => x.Remark.Contains("qw"));
            whereLambda = whereLambda.Or(x => x.IsDelete==0);
            var list = TestProducts.Products.Where(whereLambda.Compile()).AsQueryable().ToList();

            var filters = new List<Filter>() 
            {
                new Filter {Key = "Price", Value = "200", Contract = ">"},
                new Filter {Key = "Remark", Value = "qw", Contract = "like"}
            };
            var products = TestProducts.Products.AsQueryable().Where(filters).ToList();
            Console.ReadKey();
        }


        public static List<Product> GetProducts(Expression<Func<Product, bool>> whereLambda)
        {
            //var products = Products.Where(x=>x.Price>200).ToList();
            var products = TestProducts.Products.Where(whereLambda.Compile()).AsQueryable().ToList();
            return products;
        }

    }



    
}
